package com.bw.server

import android.content.Intent
import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.path.RouterPath
import com.bw.common.view.BaseMvvmFragment
import com.bw.server.databinding.FragmentServerBinding
import com.bw.server.databinding.FragmentServiceBinding
import com.bw.server.device.DeviceActivity
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class ServiceFragment : BaseMvvmFragment<FragmentServiceBinding>() {
    var adapter = ServerAdapter()
    override fun getLayoutId(): Int = R.layout.fragment_service
    val serviceList1 = listOf(
        ServerEntity1(1,"车辆管理", R.drawable.parkmanager),
        ServerEntity1(2,"车位管理",R.drawable.parkmanager2),
        ServerEntity1(3,"访客管理",R.drawable.visitor),
        ServerEntity1(4,"维修管理",R.drawable.repair_manager),
        ServerEntity1(5,"公告管理",R.drawable.notice_manager),
        ServerEntity1(6,"考勤管理",R.drawable.pmlou1),
        ServerEntity1(7,"即时通讯",R.drawable.pmlou2),
        ServerEntity1(8,"设备管理",R.drawable.pmlou3),
        ServerEntity1(9,"房源信息",R.drawable.pmlou4),
        ServerEntity1(10,"月卡会员", R.drawable.member_home),
        ServerEntity1(11,"巡逻管理",R.drawable.pmlou6),
        ServerEntity1(12,"收银台",R.drawable.pmlou7),
    )
    override fun initView() {
        mDataBinding.rv.layoutManager = GridLayoutManager(context,3)
        mDataBinding.rv.adapter = adapter
        adapter.setList(serviceList1)

        //添加item点击事件
        adapter.setOnItemClickListener { adapter, view, position ->
            val item = serviceList1[position]
            when(item.id){
                1-> //跳转到设备管理页面
                    ARouter.getInstance().build(RouterPath.PATH_CAR_PAY).navigation()
                2->
                    //跳转到设备管理页面
                    ARouter.getInstance().build("/park/activity").navigation()
                3->{}
                4->{//维修管理
                    ARouter.getInstance().build(RouterPath.PATH_REPAIR_PATH).navigation()
                }
                5->{}
                6->{}
                7->{}
                8->{
                    //跳转到设备管理页面
                    ARouter.getInstance().build(RouterPath.PATH_DEVICE_PATH).navigation()
                }
                9->//房源管理
                    ARouter.getInstance().build(RouterPath.PATH_HOUSE_PATH).navigation()
                10->{//月卡会员
                    ARouter.getInstance().build(RouterPath.PATH_VIP_PATH).navigation()
                }
                11->{//巡检模块
                    ARouter.getInstance().build(RouterPath.PATH_INSPECTION_PATH).navigation()
                }
                12->{//收银台
                    ARouter.getInstance().build(RouterPath.PATH_CASHIER_PATH).navigation()
                }
            }

        }

    }

}

data class ServerEntity1(
    val id:Int,
    val title:String,//标题
    val image:Int,//文字
)

class ServerAdapter: BaseQuickAdapter<ServerEntity1, BaseViewHolder>(R.layout.item_server) {
    override fun convert(holder: BaseViewHolder, item: ServerEntity1) {
        holder.setText(R.id.tv_title,item.title)
        val view = holder.getView<ImageView>(R.id.iv_icon)
        view.setImageResource(item.image)
    }

}